from . import mdelicious
from . import DeliciousLinks
from . import DeliciousLink
from . import DeliciousLogin

class DeliciousQuery:
    def __init__(self, delicious_login):
        self.delicious_login = delicious_login
        
    def get_links(self, tags, start_date=None, end_date=None):
    
        if isinstance(self.delicious_login, DeliciousLogin.DeliciousLogin):
            print "Using Delicious login"
            md = mdelicious.MDelicious(self.delicious_login.username, self.delicious_login.password)
        else:
            print "Using OAuth"
            md = mdelicious.MDeliciousOAuth(self.delicious_login)
        
        links = md.posts_all(tag=tags, start_date=start_date, end_date=end_date)
        result = DeliciousLinks.DeliciousLinks()
   
        for link in links:
            result.append(DeliciousLink.DeliciousLink(link["href"], link["tags"], link["description"], link["extended"], link["time"]))
        return result
    
    def show(self):
        print "U: %s" % (self.username)
